package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.SalaryFormulaConditionAddDTO;
import org.jsola.hr.dto.SalaryFormulaConditionUpdateDTO;
import org.jsola.hr.entity.SalaryFormulaConditionDO;
import org.jsola.hr.query.SalaryFormulaConditionQuery;
import org.jsola.hr.service.ISalaryFormulaConditionService;
import org.jsola.hr.vo.SalaryFormulaConditionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class SalaryFormulaConditionTestHelper extends BaseTestHelper {

    @Autowired
    private ISalaryFormulaConditionService salaryFormulaConditionService;

    /**
     * 生成add测试数据
     * @return SalaryFormulaConditionAddDTO
     */
    public SalaryFormulaConditionAddDTO getSalaryFormulaConditionAddDTO(){
        SalaryFormulaConditionAddDTO salaryFormulaConditionAddDTO = new SalaryFormulaConditionAddDTO();
        salaryFormulaConditionAddDTO.setSalaryPlanId(getRandomValue("varchar",32));
        salaryFormulaConditionAddDTO.setFormulaId(getRandomValue("varchar",32));
        salaryFormulaConditionAddDTO.setPropertyName(getRandomValue("varchar",255));
        salaryFormulaConditionAddDTO.setComparisonOperator(getRandomValue("varchar",255));
        salaryFormulaConditionAddDTO.setCondition(getRandomValue("varchar",11));
        salaryFormulaConditionAddDTO.setCompanyId(getRandomValue("varchar",32));
        return salaryFormulaConditionAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryFormulaConditionUpdateDTO
     */
    public SalaryFormulaConditionUpdateDTO getSalaryFormulaConditionUpdateDTO(SalaryFormulaConditionVO salaryFormulaConditionVO){
        return salaryFormulaConditionService.selectDOById(salaryFormulaConditionVO.getId(), SITE_ID).to(SalaryFormulaConditionUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryFormulaConditionQuery
     */
    public SalaryFormulaConditionQuery getSalaryFormulaConditionQuery() {
        SalaryFormulaConditionQuery salaryFormulaConditionQuery = new SalaryFormulaConditionQuery();
        List<SalaryFormulaConditionDO> salaryFormulaConditionDOList = salaryFormulaConditionService.list(new SalaryFormulaConditionDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryFormulaConditionDOList)) {
            SalaryFormulaConditionDO salaryFormulaConditionDO = salaryFormulaConditionDOList.get(0);
            salaryFormulaConditionQuery = salaryFormulaConditionDO.to(SalaryFormulaConditionQuery.class);
            if (salaryFormulaConditionDO.getGmtCreate() != null) {
                salaryFormulaConditionQuery.setGmtCreateStart(DateKit.getBeforeDay(salaryFormulaConditionDO.getGmtCreate(),-1));
                salaryFormulaConditionQuery.setGmtCreateEnd(DateKit.getBeforeDay(salaryFormulaConditionDO.getGmtCreate(),1));
            }
            if (salaryFormulaConditionDO.getGmtModified() != null) {
                salaryFormulaConditionQuery.setGmtModifiedStart(DateKit.getBeforeDay(salaryFormulaConditionDO.getGmtModified(),-1));
                salaryFormulaConditionQuery.setGmtModifiedEnd(DateKit.getBeforeDay(salaryFormulaConditionDO.getGmtModified(),1));
            }
        }
        return salaryFormulaConditionQuery;
    }

    /**
     * 保存示例
     * @return SalaryFormulaConditionVO
     */
    public SalaryFormulaConditionVO saveSalaryFormulaConditionExample(){
        SalaryFormulaConditionAddDTO addDTO = this.getSalaryFormulaConditionAddDTO();
        SalaryFormulaConditionVO salaryFormulaConditionVO = salaryFormulaConditionService.save(addDTO,buildTokenUser());
        return salaryFormulaConditionVO;
    }

    public List<SalaryFormulaConditionAddDTO>  getSalaryFormulaConditionAddDTOList(){
        List list=new ArrayList();
        list.add(this.getSalaryFormulaConditionAddDTO());
        list.add(this.getSalaryFormulaConditionAddDTO());
        return list;
    }

}

